'use strict';

$ = jQuery;

$(document).ready(function() {

    $('#header .menu-item-has-children').hover(function() {
        if ($(window).width() >= 1200)
            $(this).children('ul').show('400');
    }, function() {
        if ($(window).width() >= 1200)
            $(this).children('ul').hide('400');
    });
    
    $('.details').width($(window).width());
    $(window).resize(function(event) {
        $('.details').width($(window).width()); 
    });

    $('#menu-toggle').click(function(event) {
        $('#menu').toggle();
    });

    back_to_top();

});

// back to top
function back_to_top(){
    $('#back-top').on('click', function(event) {
        event.preventDefault();
        $('html,body').animate({
            scrollTop: '0'
        }, 500);
    });

    var btn = document.getElementById('back-top');
    var clientHeight = $(window).height();
    
    window.onscroll = function(){
        var ostop = document.documentElement.scrollTop||document.body.scrollTop;
        if (ostop>clientHeight) {
            btn.style.display = 'block';
        } else{
            btn.style.display = 'none';
        };
    }
}